<template>
    <view class="dialog-container">
        <view class="dialog">
            <view class="dialog-header">
                <view class="dialog-title">时间钟设置</view>
                <view class="dialog-close" @click="closeDialog">×</view>
            </view>
            <view class="dialog-body">
                <view class="form-item">
                    <label>状态：</label>
                    <picker mode="selector" :range="statusOptions" @change="onStatusChange">
                        <view class="picker">{{ statusText }}</view>
                    </picker>
                </view>
                <view class="form-item">
                    <label>时间：</label>
                    <picker mode="multiSelector" :range="timeOptions" @change="onTimeChange">
                        <view class="picker">{{ timeText }}</view>
                    </picker>
                </view>
            </view>
            <view class="dialog-footer">
                <button class="confirm-button" @click="confirm">确定</button>
            </view>
        </view>
    </view>
</template>

<script>
export default {
    data() {
        return {
            statusOptions: ['开', '关'],
            status: '开',
            hours: '00',
            minutes: '00',
            timeOptions: [
                Array.from({ length: 24 }, (_, i) => String(i).padStart(2, '0')),
				// ['小时'],
                Array.from({ length: 60 }, (_, i) => String(i).padStart(2, '0')),
				// ['分钟'],
            ],
        };
    },
    computed: {
        statusText() {
            return this.status;
        },
        timeText() {
            return `${this.hours}:${this.minutes}`;
        }
    },
    methods: {
        onStatusChange(event) {
            this.status = this.statusOptions[event.detail.value];
        },
        onTimeChange(event) {
            const [hourIndex, minuteIndex] = event.detail.value;
            this.hours = this.timeOptions[0][hourIndex];
            this.minutes = this.timeOptions[1][minuteIndex];
			console.log(this.timeOptions[1][minuteIndex]);
			console.log(this.timeOptions[0][hourIndex]);
        },
        confirm() {
            const time = `${this.hours}:${this.minutes}:00`;
            this.$emit('confirm', { status: this.status, time });
        },
        closeDialog() {
            this.$emit('close');
        }
    }
};
</script>

<style scoped>
.dialog-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.dialog {
    width: 80%;
    background-color: white;
    border-radius: 10px;
    overflow: hidden;
    z-index: 1001;
}

.dialog-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background-color: #f5f5f5;
}

.dialog-title {
    font-size: 18px;
}

.dialog-close {
    font-size: 18px;
    cursor: pointer;
}

.dialog-body {
    padding: 20px;
}

.form-item {
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

label {
    flex: 1;
}

.picker {
    flex: 2;
    /* border: 1px solid #ccc; */
    padding: 5px;
    text-align: center;
}

.dialog-footer {
    display: flex;
    justify-content: center;
    padding: 10px;
    background-color: #f5f5f5;
}

.confirm-button {
    padding: 1px 20px;
    background-color: #4e6490;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}
</style>
